package com.hmall.item.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.ItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void updateStatusById(Long id, Integer status) {
        this.update().set("status", status).eq("id", id).update();
        String routingKey = status == 1 ? "item.up" : "item.down";
        rabbitTemplate.convertAndSend("item.topic", routingKey, id);
    }
}
